<template>
  <div class="clock">
    <p class="time">{{time}}</p>
    <p class="date" v-html="date"></p>
  </div>
</template>
<script>
export default {
  name: 'Clock',
  data () {
    return {
      time: '',
      date: '',
      week: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
    }
  },
  methods: {
    updateTime () {
      const cd = new Date()
      this.time = this.zeroPadding(cd.getHours(), 2) + ':' + this.zeroPadding(cd.getMinutes(), 2)
      this.date = this.zeroPadding(cd.getFullYear(), 4) + '/' + this.zeroPadding(cd.getMonth() + 1, 2) + '/' + this.zeroPadding(cd.getDate(), 2) + '<br />' + this.week[cd.getDay()]
    },
    zeroPadding (num, digit) {
      let zero = ''
      for (let i = 0; i < digit; i++) {
        zero += '0'
      }
      return (zero + num).slice(-digit)
    }
  },
  mounted () {
    setInterval(this.updateTime, 1000)
  }
}
</script>
<style lang="stylus" scoped>
  .time
    float: left
    font-size: 32px
    line-height: 75px;
  .date
    float: left
    line-height: 16px
    font-size: 12px
    padding: 19px 9px
</style>
